/*+***********************************
Filename: vectors.s
Description: reset entry.
Modification:
2023.04.21 hzheng creation
2023.08.02 hzheng add isr

************************************-*/
     
## reset entry section
##
    .section .text.entry
    .global _start
    .type _start, @function
_start:
## set led on
    lui  a5,0x50006
    li      s0,4
    sh      s0,4(a5)   #GPIO_DIR=0x50006004
    li      s0,4       #0 or 4
    sh      s0,0(a5)   #GPIO_ODR=0x50006000

## shutdown watchdog
    lui a4,0x50000       #0x5000_0048
    lhu a5,48(a4)
    slli    a5,a5,0x10
    srli    a5,a5,0x10
    andi    a5,a5,-2
    slli    a5,a5,0x10
    srli    a5,a5,0x10
    sh  a5,48(a4)

## set sp
    la sp, __SYSTEM_STACK_END__

## set interrupt vector
    la t0, trap_vector
    csrw	mtvec,t0

## enable global mie
    csrsi  mstatus,0x08
    
## call main
    la     t0, main
    jalr   t0
    
## dead_loop
    j .  

    
## isr
    .global myisr

    .type isr_wrapper, @function
isr_wrapper:
    la     t0, myisr
    jalr   t0
    mret
    
## trap_vector
    .align 2
trap_vector:
    j isr_wrapper
